Beispiel #1
0
    /*
     * public static void DestroyComponentInPrefab<T>(this GameObject go) {
     *      bool isPrefabInstance = PrefabUtility.GetPrefabParent(go) != null && PrefabUtility.GetPrefabObject(go.transform) != null;
     *      if (isPrefabInstance) {
     *              GameObject clone = GameObject.Instantiate(go, Vector3.zero, Quaternion.identity) as GameObject;
     *              DestroyImmediate (clone.GetComponentInChildren (T).gameObject);
     *              PrefabUtility.ReplacePrefab (clone, PrefabUtility.GetPrefabParent (go));
     *              GameObject.DestroyImmediate(clone);
     *      } else {
     *              DestroyImmediate (go.GetComponentInChildren<FirearmLinker> ().gameObject);
     *      }
     * }
     */

    public void DrawButtons()
    {
        if (!Application.isPlaying)
        {
            return;
        }

        PropLinker myScript = (PropLinker)target;

        if (myScript.interactable != null)
        {
            var hand = myScript.interactable.attachedToHand;
            if (hand)
            {
                if (GUILayout.Button("Update Controller Offset"))                   //must be done in game
                {
                    UpdateObjOffset(myScript);
                }
            }
            else
            {
                if (GUILayout.Button("Move To Right Hand"))                   //must be done in game
                {
                    SetObjOffset(myScript.gameObject, Player.instance.rightHand);
                }
                if (GUILayout.Button("Move To Left Hand"))                   //must be done in game
                {
                    SetObjOffset(myScript.gameObject, Player.instance.leftHand);
                }
            }
        }
    }
Beispiel #2
0
    public static void UpdateObjOffset(PropLinker sceneObject)
    {
        var offset = sceneObject.transform.Find("ControllerOffset");

        if (offset != null)
        {
            offset.localPosition = sceneObject.offsetPos;
            offset.localRotation = sceneObject.offsetRot;

            Selection.activeGameObject = offset.gameObject;
        }
    }
Beispiel #3
0
    public override void OnInspectorGUI()
    {
        GUIStyle customLabel;

        EditorGUILayout.Space();
        customLabel                  = new GUIStyle("Label");
        customLabel.alignment        = TextAnchor.LowerLeft;
        customLabel.fontSize         = 14;
        customLabel.normal.textColor = Color.black;
        customLabel.fontStyle        = FontStyle.Normal;

        PropLinker myScript = (PropLinker)target;

        switch (myScript.propType)
        {
        case PropLinker.PropType.simple:
            GUILayout.Label("Simple Grabbable Prop", customLabel);

            if (myScript.GetComponentInChildren <FirearmLinker> () != null)
            {
                EditorGUILayout.Space();

                customLabel                  = new GUIStyle("Label");
                customLabel.alignment        = TextAnchor.MiddleCenter;
                customLabel.fontSize         = 12;
                customLabel.normal.textColor = Color.red;
                customLabel.fontStyle        = FontStyle.BoldAndItalic;

                GUILayout.Label("Some components should be removed!", customLabel);

                if (GUILayout.Button("Remove Unused Components"))
                {
                    var go = myScript.gameObject;
                    go.DestroyComponentInPrefab <FirearmLinker> ();


                    //go.DestroyComponentInPrefab<FirearmLinker> ();
                }
            }
            break;

        case PropLinker.PropType.firearm:
            GUILayout.Label("Gun/Firearm Prop", customLabel);

            if (myScript.GetComponentInChildren <FirearmLinker> () == null)
            {
                EditorGUILayout.Space();

                customLabel                  = new GUIStyle("Label");
                customLabel.alignment        = TextAnchor.MiddleCenter;
                customLabel.fontSize         = 12;
                customLabel.normal.textColor = Color.red;
                customLabel.fontStyle        = FontStyle.BoldAndItalic;

                GUILayout.Label("Firearm script has not been added!", customLabel);

                if (GUILayout.Button("Add Firearm Helpers"))
                {
                    var firingPointPrefabPath = "Assets/AnimPrep/Prefabs/FiringPoint.prefab";

                    UnityEngine.Object firingPointPrefab = AssetDatabase.LoadAssetAtPath(firingPointPrefabPath, typeof(GameObject));
                    GameObject         firingPointObject = GameObject.Instantiate(firingPointPrefab, Vector3.zero, Quaternion.identity) as GameObject;
                    firingPointObject.name = firingPointPrefab.name;

                    firingPointObject.transform.parent        = myScript.transform;
                    firingPointObject.transform.localPosition = Vector3.zero;
                    firingPointObject.transform.localRotation = Quaternion.identity;

                    //myScript.gameObject.AddComponent<FirearmLinker> ();
                }
            }
            break;
        }

        DrawButtons();

        DrawDefaultInspector();

        serializedObject.ApplyModifiedProperties();
    }