public T SetManagedShape <T>() where T : CurvyShape2D { if (!Shape) { Shape = (CurvySpline)AddManagedResource("Shape"); } CurvyShape sh = Shape.GetComponent <CurvyShape>(); if (sh != null) { sh.Delete(); } return(Shape.gameObject.AddComponent <T>()); }
public override bool OnGUI() { bool dirty = false; bool b = GUILayout.Toggle(mFreeform, "Freeform"); if (b != mFreeform) { if (b) { mCurrentShape.Spline.ShowGizmos = true; mCurrentShape.Delete(); mCurrentShape = null; mFreeform = b; } else if (EditorUtility.DisplayDialog("Warning", "The current shape will be irreversible replaced. Are you sure?", "Ok", "Cancel")) { mFreeform = b; mCurrentShape = (CurvyShape2D)Resource.gameObject.AddComponent(CurvyShape.GetShapeType(mMenuNames[mSelection])); mCurrentShape.Dirty = true; mCurrentShape.Spline.ShowGizmos = false; } } if (!mFreeform) { int sel = EditorGUILayout.Popup(mSelection, mMenuNames); if (sel != mSelection) { mSelection = sel; dirty = true; if (mCurrentShape) { mCurrentShape.Delete(); } mCurrentShape = (CurvyShape2D)Resource.gameObject.AddComponent(CurvyShape.GetShapeType(mMenuNames[mSelection])); mCurrentShape.Dirty = true; } if (mCurrentShape) { var so = new SerializedObject(mCurrentShape); var prop = so.GetIterator(); bool enterChildren = true; while (prop.NextVisible(enterChildren)) { switch (prop.name) { case "m_Script": case "InspectorFoldout": case "m_Plane": //case "m_Persistent": break; default: EditorGUILayout.PropertyField(prop); break; } enterChildren = false; } dirty = dirty || so.ApplyModifiedProperties(); } } return(dirty); }
public CGShapeResourceGUI(Component resource) : base(resource) { mCurrentShape = resource.GetComponent <CurvyShape2D>(); mMenuNames = CurvyShape.GetShapesMenuNames((mCurrentShape) ? mCurrentShape.GetType() : null, out mSelection, true).ToArray(); mFreeform = (mCurrentShape == null); }