Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
1
Question by fuzzalicious · Nov 13, 2015 at 05:56 AM · particlesinspectorcustom editor

Custom Inspector for Particle System

Im making a custom inspector for the particle system, I have a slider which alters the emission rate. I have 2 problems:
1. The particle system is no longer rendered in scene view.
2. The slider immediately reverts. If I play the game I can use the slider to change the emission but the slider dosn't move (or returns next frame). The same is true for the floatField.

 using UnityEngine;
 using System.Collections;
 using UnityEditor;
 
 [CustomEditor(typeof(ParticleSystem))]
 public class ParticleCustomizer : Editor {
     private ParticleSystem ps;
 
     public override void OnInspectorGUI() {
         ps = (ParticleSystem)target;
         ps.emissionRate = EditorGUILayout.Slider("Emission:", 50, 0, 100);        
     }
 }
 

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by mikelortega · Nov 13, 2015 at 09:13 AM

The second problem is you should set the slider value to ps.emissionRate, like this:

 ps.emissionRate = EditorGUILayout.Slider("Emission:", ps.emissionRate, 0, 100);

But the thing is, you shouldn't overwrite the particle system's default editor inspector. This inspector allows you simulating in edit time and many other things that you shouldn't overwrite.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by fuzzalicious · Nov 13, 2015 at 03:42 PM

Ah, of course. ^^ As for overwriting, I want to add functionality to the editor like randomization, don't I then have to overwrite?

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mikelortega · Nov 13, 2015 at 07:00 PM 0
Share

To do that, I would create a new component that implements your randomization functionality, and add it to the gameobject that contains the particle system. So you have a GameObject with the particle system and your own functionality next to it.

avatar image fuzzalicious mikelortega · Nov 18, 2015 at 01:03 PM 0
Share

How do I go about accessing the particle in edit mode when using a custom class? When I overrode the particle I could access it simply using Editor.target. Now I have an empty custom class which uses [RequireComponent(typeof(UnityEngine.ParticleSystem))] and then another class as an editor for the custom class.

avatar image mikelortega fuzzalicious · Nov 18, 2015 at 01:27 PM 0
Share

I mean using a new component and it's editor. Something like this:

ParticleCustomizer.cs

 using UnityEngine;
 
 [ExecuteInEdit$$anonymous$$ode]
 [RequireComponent(typeof(ParticleSystem))]
 public class ParticleCustomizer : $$anonymous$$onoBehaviour
 {
     ParticleSystem m_Ps;
 
     void Start()
     {
         m_Ps = GetComponent<ParticleSystem>();
     }
 
     public float emissionRate
     {
         set { m_Ps.emissionRate = value; }
         get { return m_Ps.emissionRate; }
     }
 
 }

EditParticleCustomizer.cs

 using UnityEngine;
 using UnityEditor;
 
 [CustomEditor(typeof(ParticleCustomizer))]
 public class EditParticleCustomizer : Editor
 {
     public override void OnInspectorGUI()
     {
         ParticleCustomizer pc = (ParticleCustomizer)target;
         pc.emissionRate = EditorGUILayout.Slider("Emission:", pc.emissionRate, 0, 100);
     }
 }


Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

35 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Custom Editor: Array of Structs with elements hidden by toggles 0 Answers

How can I edit InputField's Inspector? 0 Answers

Dynamically sized list of toggles in custom inspector? 0 Answers

Custom Editor List with child classes 1 Answer

error CS0246: The type or namespace name 'MonoScript' could not be found (are you missing a using directive or an assembly reference?) 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges