コード例 #1
0
 public override void OnClick(Click type)
 {
     foreach (Clickable clickable in Target?.GetComponents <Clickable>())
     {
         clickable.OnClick(type);
     }
 }
コード例 #2
0
        public static void SendMessage(this GameObject sender, GameMessage msg, GameObject target)
        {
            if (msg == null)
            {
                Log.Game.WriteWarning("ExtMethodsGameObject: Tried to send a null message.\n{0}", Environment.StackTrace);
                return;
            }

            // if there is already a list on the stack then we have re-entered SendMessage i.e. a HandleMessage method has
            // called SendMessage
            if (_receiverStack.Count > 0)
                _currentReceivers = new List<ICmpHandlesMessages>();

            _receiverStack.Push(_currentReceivers);
            _currentReceivers.Clear();

            if (target != null)
            {
                if (!target.Active)
                {
                    _currentReceivers = _receiverStack.Pop();
                    return;
                }

                target.GetComponents(_currentReceivers);
            }
            else
            {
                Scene.Current.FindComponents(_currentReceivers);
            }

            try
            {
                for (int i = _currentReceivers.Count - 1; i >= 0; i--)
                {
                    var receiver = _currentReceivers[i];

                    if (receiver == null || ((Component)receiver).Disposed || ((Component)receiver).Active == false)
                        continue;

                    receiver.HandleMessage(sender, msg);

                    if (i > _currentReceivers.Count)
                        i = _currentReceivers.Count;

                    if (msg.Handled)
                        break;
                }
            }
            finally
            {
                _receiverStack.Pop();
                if (_receiverStack.Count > 0)
                    _currentReceivers = _receiverStack.Peek();
                else
                    _currentReceivers = _receivers;
            }
        }
コード例 #3
0
        public void WeCanFindAllComponentsByItsSubType()
        {
            GameObject go = new GameObject();
            go.AddComponent(typeof(TestComponent));

            UnityObject[] uo = go.GetComponents(typeof(Component));

            Assert.That(uo, Is.Not.Null);
            Assert.That(uo.Length, Is.EqualTo(2));
        }
コード例 #4
0
        private static void BrightenGameObject(GameObject obj)
        {
            MeshRenderer mesh = TryGet(obj?.GetComponents <MeshRenderer>(), 0, null, "MovementDot MeshRenderer");

            if (mesh == null)
            {
                return;
            }
            Color.RGBToHSV(mesh.sharedMaterial.color, out float H, out _, out _);
            mesh.sharedMaterial.color = Color.HSVToRGB(H, 1, 1);
        }
コード例 #5
0
        private void HideRestrictedAxis()
        {
            var gizmo = GetActiveGizmo();

            if (gizmo == null)
            {
                return;
            }

            var axisRestrictions = _selectedObject?.GetComponents <SrRestrictAxis>()?.Where(ar => ar.GizmoType == gizmo.GizmoType) ?? Enumerable.Empty <SrRestrictAxis>();

            var srRestrictAxises = axisRestrictions as SrRestrictAxis[] ?? axisRestrictions.ToArray();

            foreach (var axis in gizmo.AxisList ?? Enumerable.Empty <SrGizmoAxis>())
            {
                foreach (var mesh in axis.GizmoMeshes)
                {
                    mesh.enabled = srRestrictAxises.Any(ar => ar.RestrictAxisTo == axis.SrAxis) || !srRestrictAxises.Any();
                }
            }
        }
コード例 #6
0
        public void AddObject(GameObject gameObject)
        {
            if (gameObject == null) throw new ArgumentNullException("gameObject");
            _addNewObjectsQueue.Enqueue(gameObject);
            gameObject.GameObjectManager = this;

            var components = gameObject.GetComponents<ColliderComponent>();
            foreach (var item in components)
            {
                QuadTree.Insert(item as ColliderComponent);
            }
        }
コード例 #7
0
    public static bool IsMute(this GameObject g)
    {
        bool mute = true;

        foreach (AudioSource s in g?.GetComponents <AudioSource>())
        {
            if (!s.mute)
            {
                mute = false;
            }
        }
        return(mute);
    }
コード例 #8
0
        public override ExtendedEventArgs process()
        {
            Debug.Log ("response process--");

            g = GameObject.Find("Player_sprite_2(Clone)");
            p2 = g.GetComponents<PlayerController2> ();

            p2[0].keytype = keytype;
            p2 [0].key = key;
            ResponseKeyboardEventArgs args = new ResponseKeyboardEventArgs ();
            args.keytype = keytype;
            args.key = key;

            return args;
        }
コード例 #9
0
ファイル: WhenSettingNewIds.cs プロジェクト: Joelone/FFWD
        public void TheIdMapWillContainAMapOfAllComponents()
        {
            Dictionary<int, UnityObject> ids = new Dictionary<int, UnityObject>();
            GameObject go = new GameObject();
            go.AddComponent(typeof(TestComponent));
            go.AddComponent(typeof(TestComponent));

            go.SetNewId(ids);

            Assert.That(ids.Count, Is.EqualTo(4));
            foreach (var item in go.GetComponents(typeof(Component)))
            {
                Assert.That(ids.ContainsValue(item), Is.True);
            }
        }
コード例 #10
0
 bool IsLogging(GameObject go)
 {
     Stepper[] steppers = go?.GetComponents <Stepper>();
     if (steppers == null || steppers.Length == 0)
     {
         return(false);
     }
     foreach (var k in steppers)
     {
         if (k.isLogging)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #11
0
        int ActiveStepperCount(GameObject go)
        {
            Stepper[] steppers = go?.GetComponents <Stepper>();
            if (steppers == null || steppers.Length == 0)
            {
                return(0);
            }
            int c = 0;

            foreach (var k in steppers)
            {
                if (k.isLogging)
                {
                    c++;
                }
            }
            return(c);
        }
コード例 #12
0
 private void Death()
 {
     deathTween = DOTween.To(() => mcamera.GetComponents <PostProcessVolume>()[2].weight, x => mcamera.GetComponents <PostProcessVolume>()[2].weight = x, 1f, 2f);
     coroutine  = DeathRoutine();
     StartCoroutine(coroutine);
 }
コード例 #13
0
ファイル: ToolGameObjectFinder.cs プロジェクト: smith076/Snap
    private List <GameObjectListing> Filter(GameObjectListing[] gameObjectListings)
    {
        string filterString = _caseSensitive ? _filterString : _filterString.ToLower();

        string[] filterSubstrings = filterString.Split(new char[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries);

        var filtered = new List <GameObjectListing>();

        if (gameObjectListings == null)
        {
            return(filtered);
        }
        foreach (var listing in gameObjectListings)
        {
            GameObject go = listing.GameObject;

            // check substrings
            bool passSubstringFilter = true;
            foreach (var substring in filterSubstrings)
            {
                if (_caseSensitive ? !go.name.Contains(substring) : !go.name.ToLower().Contains(substring))
                {
                    passSubstringFilter = false;
                    break;
                }
            }
            if (!passSubstringFilter)
            {
                continue;
            }

            // check missing script
            if (_filterUnassignedScript)
            {
                bool passMissingScriptFilter = false;
                var  components = go.GetComponents <Component>();
                foreach (var component in components)
                {
                    if (component == null)
                    {
                        passMissingScriptFilter = true;
                        break;
                    }
                }
                if (!passMissingScriptFilter)
                {
                    continue;
                }
            }

            // check layer
            if (_filterLayer && _invertLayerFilter != (_filteredLayer != go.layer))
            {
                continue;
            }

            // check tag
            if (_filterTag && _invertTagFilter != (!go.CompareTag(_filteredTag)))
            {
                continue;
            }

            // check component
            if (_filterComponent)
            {
                System.Type componentType = _componentTypes[_filteredComponentIndex];
                if (componentType != null)
                {
                    var component = go.GetComponent(componentType);
                    if (_invertComponentFilter && component != null || !_invertComponentFilter && component == null)
                    {
                        continue;
                    }

                    if (!_invertComponentFilter && _filterComponentIsCollider && FilterColliderComponent(component))
                    {
                        continue;
                    }
                }
            }

            // check script
            if (_filterScript && _filteredScript != null && _invertScriptFilter != (go.GetComponent(_filteredScript.GetClass()) == null))
            {
                continue;
            }

            // check static
            if (_filterStatic && _invertStaticFilter != !GameObjectUtility.AreStaticEditorFlagsSet(go, _filteredStaticFlag))
            {
                continue;
            }

            // add gameobject to filtered set
            filtered.Add(listing);
        }

        return(filtered);
    }
コード例 #14
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        if (property.propertyType != SerializedPropertyType.ObjectReference)
        {
            return;
        }

        var attrib = this.attribute as InterfaceAttribute;

        if (attrib == null)
        {
            return;
        }

        EditorGUI.BeginChangeCheck();
        Object obj = EditorGUI.ObjectField(
            position,
            label,
            property.objectReferenceValue,
            typeof(Object),
            attrib.allowSceneObjects
            );

        if (EditorGUI.EndChangeCheck())
        {
            var name = obj.name;
            if (obj != null)
            {
                var type = obj.GetType();
                if (!attrib.type.IsAssignableFrom(type))
                {
                    GameObject boxing = null;
                    if (obj is GameObject)
                    {
                        boxing = (obj as GameObject);
                    }
                    else if (obj is Component)
                    {
                        obj = (obj as Component).gameObject;
                    }

                    var components         = boxing?.GetComponents(attrib.type);
                    var numberOfComponents = components.Length;
                    if (numberOfComponents <= 0)
                    {
                        obj = null;
                    }
                    else if (numberOfComponents == 1)
                    {
                        obj = components[0];
                    }
                    else
                    {
                        obj = components[0];
                        Debug.LogWarning($"{numberOfComponents} components founded, first one automatically selected");
                    }
                }
            }
            if (null == obj)
            {
                Debug.LogError($"[{name}] Interface implementation not found");
            }

            property.objectReferenceValue = obj;
        }
    }
コード例 #15
0
ファイル: LuaHelper.cs プロジェクト: FlameskyDexive/hugula
 public static Component[] GetComponents(GameObject obj, System.Type t)
 {
     Component[] comp = null;
     if (obj != null && t!=null) comp = obj.GetComponents(t);
     return comp;
 }
コード例 #16
0
 // Use this for initialization
 void Start()
 {
     player          = GameObject.Find("Player Prefab");
     playerColliders = player.GetComponents <Collider2D> ();
     thisColliders   = GetComponents <Collider2D>();
 }
コード例 #17
0
    static public GameObject DoCopyObjects(GameObject from)
    {
        MegaModifyObject fromMod = from.GetComponent <MegaModifyObject>();

        GameObject to;

        if (fromMod)
        {
            to = CopyMesh(from, fromMod);
        }
        else
        {
            to = CopyMesh(from);
        }
        //CopyObject.CopyFromTo(from, to);

        //return to;
        //MegaModifier[] desmods = to.GetComponents<MegaModifier>();
        //for ( int i = 0; i < desmods.Length; i++ )
        //{
        //	GameObject.DestroyImmediate(desmods[i]);
        //}

        //MegaModifyObject mo = to.GetComponent<MegaModifyObject>();
        //if ( mo )
        //{
        //GameObject.DestroyImmediate(mo);
        MegaModifyObject mo = to.AddComponent <MegaModifyObject>();

        CopyModObj(fromMod, mo);
        //}

        MegaModifier[] mods = from.GetComponents <MegaModifier>();

        for (int i = 0; i < mods.Length; i++)
        {
            Component com = CopyComponent(mods[i], to);

            //Type tp = com.GetType();
#if false
            if (tp.IsSubclassOf(typeof(MegaMorphBase)))
            {
                MegaMorphBase mor = (MegaMorphBase)com;
                // Need to rebuild the morphchan
                List <MegaMorphChan> chans = new List <MegaMorphChan>();

                for (int c = 0; c < mor.chanBank.Count; c++)
                {
                    MegaMorphChan chan = new MegaMorphChan();

                    MegaMorphChan.Copy(mor.chanBank[c], chan);
                    chans.Add(chan);
                }

                mor.chanBank = chans;
            }
#endif

#if false
            if (tp.IsSubclassOf(typeof(MegaFFD)))
            {
                MegaFFD ffd    = (MegaFFD)com;
                MegaFFD srcffd = (MegaFFD)mods[i];

                ffd.pt = new Vector3[64];

                for (int c = 0; c < 64; c++)
                {
                    ffd.pt[c] = srcffd.pt[c];
                }
            }
#endif
            // TODO: Add method to modifiers so can deal with any special cases

            if (com)
            {
                MegaModifier mod = (MegaModifier)com;
                mod.PostCopy(mods[i]);
            }
        }

        if (mo)
        {
            //mod.ReStart1(false);

            //for ( int i = 0; i < mods.Length; i++ )
            //	mods[i].SetModMesh(mod.cachedMesh);
            mo.MeshUpdated();
        }
        to.name = from.name + " - Copy";
        return(to);
    }
コード例 #18
0
 // ignore collisions on the server
 public override void OnStartClient()
 {
     source = ClientScene.FindLocalObject(spawnedBy);
     Physics2D.IgnoreCollision(GetComponent <Collider2D>(), source.GetComponents <Collider2D>()[0]);
     Physics2D.IgnoreCollision(GetComponent <Collider2D>(), source.GetComponents <Collider2D>()[1]);
 }
コード例 #19
0
 bool HasMissingScript(GameObject go)
 {
     return(go.GetComponents <Component>().Any(c => !c));
 }
コード例 #20
0
    /// <summary>
    /// Collect a list of usable properties and fields.
    /// </summary>

    static public List <Entry> GetProperties(GameObject target, bool read, bool write)
    {
        var comps = target.GetComponents <Component>();

        var list = new List <Entry>();

        for (int i = 0, imax = comps.Length; i < imax; ++i)
        {
            var comp = comps[i];
            if (comp == null)
            {
                continue;
            }

            var type   = comp.GetType();
            var flags  = BindingFlags.Instance | BindingFlags.Public;
            var fields = type.GetFields(flags);
            var props  = type.GetProperties(flags);

            // The component itself without any method
            if (PropertyReference.Convert(comp, filter))
            {
                var ent = new Entry();
                ent.target = comp;
                list.Add(ent);
            }

            for (var b = 0; b < fields.Length; ++b)
            {
                var field = fields[b];

                if (filter != typeof(void))
                {
                    if (canConvert)
                    {
                        if (!PropertyReference.Convert(field.FieldType, filter))
                        {
                            continue;
                        }
                    }
                    else if (!filter.IsAssignableFrom(field.FieldType))
                    {
                        continue;
                    }
                }

                var ent = new Entry();
                ent.target = comp;
                ent.name   = field.Name;
                list.Add(ent);
            }

            for (var b = 0; b < props.Length; ++b)
            {
                var prop = props[b];
                if (read && !prop.CanRead)
                {
                    continue;
                }
                if (write && !prop.CanWrite)
                {
                    continue;
                }

                if (filter != typeof(void))
                {
                    if (canConvert)
                    {
                        if (!PropertyReference.Convert(prop.PropertyType, filter))
                        {
                            continue;
                        }
                    }
                    else if (!filter.IsAssignableFrom(prop.PropertyType))
                    {
                        continue;
                    }
                }

                var ent = new Entry();
                ent.target = comp;
                ent.name   = prop.Name;
                list.Add(ent);
            }
        }
        return(list);
    }
コード例 #21
0
    internal void InitAssetInfo()
    {
        AssetInfo = new List <AssetViewerInfo>();

        DirectoryInfo [] subDirectories = Directory.GetDirectories("*", SearchOption.TopDirectoryOnly);
        for (int i = 0; i < subDirectories.Length; ++i)
        {
            if (subDirectories[i].FullName.Contains("~") && !Directory.Parent.FullName.Contains("~"))
            {
                IsExpanded = true;
            }

            ContainsSubDirectories = true;
            AssetInfo.Add(new AssetViewerInfo(subDirectories[i], subDirectories[i].FullName.Replace("~", string.Empty)));
        }

        //	ignore all files with .meta or .DS_Store
        FileInfo [] files = Directory.GetFiles("*", SearchOption.TopDirectoryOnly).
                            Where(o => !o.Name.EndsWith(".meta") && !o.Name.EndsWith(".DS_Store")).ToArray();

        for (int i = 0; i < files.Length; ++i)
        {
            AssetInfo.Add(new AssetViewerInfo(files[i], files[i].FullName.Replace("~", string.Empty)));
        }

        //	set up all the asset info to detect missing components
        for (int i = 0; i < AssetInfo.Count; ++i)
        {
            AssetInfo[i].MissingComponents = new List <string>();

            Object     obj  = AssetDatabase.LoadAssetAtPath(AssetInfo[i].FileSystemInfo.FullName.RemoveProjectPath(), typeof(Object));
            GameObject gObj = obj as GameObject;

            if (gObj != null)
            {
                Component [] components = gObj.GetComponents(typeof(Component));
                for (int a = 0; a < components.Length; ++a)
                {
                    SerializedObject   s = new SerializedObject(components[a]);
                    SerializedProperty o = s.GetIterator();
                    while (o.NextVisible(true))
                    {
                        if (o.propertyType == SerializedPropertyType.ObjectReference)
                        {
                            if (o.objectReferenceValue == null && o.objectReferenceInstanceIDValue != 0)
                            {
                                AssetInfo[i].MissingComponents.Add("MISSING " + o.displayName);
                            }
                        }
                    }
                }
            }

            string [] dependencies = AssetDatabase.GetDependencies(AssetInfo[i].FileSystemInfo.FullName.RemoveProjectPath(), false);

            for (int j = 0; j < dependencies.Length; ++j)
            {
                FileInfo file = new FileInfo(dependencies[j]);
                AssetInfo[i].Dependencies.Add(new AssetViewerInfo(file, file.FullName.Replace("~", string.Empty)));
            }
        }
    }
コード例 #22
0
        void Update()
        {
            if (!CommonScriptableObjects.rendererState.Get() || charCamera == null)
            {
                return;
            }

            // We use Physics.Raycast() instead of our raycastHandler.Raycast() as that one is slower, sometimes 2x, because it fetches info we don't need here
            if (!Physics.Raycast(GetRayFromCamera(), out hitInfo, Mathf.Infinity, PhysicsLayers.physicsCastLayerMaskWithoutCharacter))
            {
                clickHandler = null;
                UnhoverLastHoveredObject();
                return;
            }

            var raycastHandlerTarget = hitInfo.collider.GetComponent <IRaycastPointerHandler>();

            if (raycastHandlerTarget != null)
            {
                ResolveGenericRaycastHandlers(raycastHandlerTarget);
                UnhoverLastHoveredObject();
                return;
            }

            if (CollidersManager.i.GetColliderInfo(hitInfo.collider, out ColliderInfo info))
            {
                newHoveredEvent = info.entity.gameObject.GetComponentInChildren <OnPointerEvent>();
            }
            else
            {
                newHoveredEvent = hitInfo.collider.GetComponentInChildren <OnPointerEvent>();
            }

            clickHandler = null;

            if (!EventObjectCanBeHovered(newHoveredEvent, info))
            {
                UnhoverLastHoveredObject();
                return;
            }

            newHoveredObject = newHoveredEvent.gameObject;

            if (newHoveredObject != lastHoveredObject)
            {
                UnhoverLastHoveredObject();

                lastHoveredObject    = newHoveredObject;
                lastHoveredEventList = newHoveredObject.GetComponents <OnPointerEvent>();
                OnPointerHoverStarts?.Invoke();
            }

            // OnPointerDown/OnClick and OnPointerUp should display their hover feedback at different moments
            if (lastHoveredEventList != null && lastHoveredEventList.Length > 0)
            {
                for (int i = 0; i < lastHoveredEventList.Length; i++)
                {
                    OnPointerEvent e = lastHoveredEventList[i];

                    bool eventButtonIsPressed = InputController_Legacy.i.IsPressed(e.GetActionButton());

                    if (e is OnPointerUp && eventButtonIsPressed)
                    {
                        e.SetHoverState(true);
                    }
                    else if ((e is OnPointerDown || e is OnClick) && !eventButtonIsPressed)
                    {
                        e.SetHoverState(true);
                    }
                    else
                    {
                        e.SetHoverState(false);
                    }
                }
            }

            newHoveredObject = null;
            newHoveredEvent  = null;
        }
コード例 #23
0
ファイル: SceneDebugger.cs プロジェクト: valdeman88/Nitrox
        private void RenderTabGameObject()
        {
            using (new GUILayout.VerticalScope("Box"))
            {
                if (selectedObject)
                {
                    using (GUILayout.ScrollViewScope scroll = new GUILayout.ScrollViewScope(gameObjectScrollPos))
                    {
                        gameObjectScrollPos = scroll.scrollPosition;
                        RenderToggleButtons($"GameObject: {selectedObject.name}");

                        using (new GUILayout.VerticalScope("Box"))
                        {
                            using (new GUILayout.HorizontalScope())
                            {
                                selectedObjectActiveSelf = GUILayout.Toggle(selectedObjectActiveSelf, "Active");
                            }

                            GUILayout.Label("Position");
                            using (new GUILayout.HorizontalScope())
                            {
                                float.TryParse(GUILayout.TextField(selectedObjectPos.x.ToString()), NumberStyles.Float, CultureInfo.InvariantCulture, out selectedObjectPos.x);
                                float.TryParse(GUILayout.TextField(selectedObjectPos.y.ToString()), NumberStyles.Float, CultureInfo.InvariantCulture, out selectedObjectPos.y);
                                float.TryParse(GUILayout.TextField(selectedObjectPos.z.ToString()), NumberStyles.Float, CultureInfo.InvariantCulture, out selectedObjectPos.z);
                            }

                            GUILayout.Label("Rotation");
                            using (new GUILayout.HorizontalScope())
                            {
                                float.TryParse(GUILayout.TextField(selectedObjectRot.x.ToString()), NumberStyles.Float, CultureInfo.InvariantCulture, out selectedObjectRot.x);
                                float.TryParse(GUILayout.TextField(selectedObjectRot.y.ToString()), NumberStyles.Float, CultureInfo.InvariantCulture, out selectedObjectRot.y);
                                float.TryParse(GUILayout.TextField(selectedObjectRot.z.ToString()), NumberStyles.Float, CultureInfo.InvariantCulture, out selectedObjectRot.z);
                                float.TryParse(GUILayout.TextField(selectedObjectRot.w.ToString()), NumberStyles.Float, CultureInfo.InvariantCulture, out selectedObjectRot.w);
                            }

                            GUILayout.Label("Scale");
                            using (new GUILayout.HorizontalScope())
                            {
                                float.TryParse(GUILayout.TextField(selectedObjectScale.x.ToString()), NumberStyles.Float, CultureInfo.InvariantCulture, out selectedObjectScale.x);
                                float.TryParse(GUILayout.TextField(selectedObjectScale.y.ToString()), NumberStyles.Float, CultureInfo.InvariantCulture, out selectedObjectScale.y);
                                float.TryParse(GUILayout.TextField(selectedObjectScale.z.ToString()), NumberStyles.Float, CultureInfo.InvariantCulture, out selectedObjectScale.z);
                            }
                        }

                        foreach (MonoBehaviour behaviour in selectedObject.GetComponents <MonoBehaviour>())
                        {
                            using (new GUILayout.HorizontalScope("Box"))
                            {
                                if (GUILayout.Button(behaviour.GetType().Name))
                                {
                                    selectedMonoBehaviour = behaviour;
                                    ActiveTab             = GetTab("MonoBehaviour").Get();
                                }
                            }
                        }
                    }
                }
                else
                {
                    GUILayout.Label($"No selected GameObject\nClick on an object in '{GetTab("Hierarchy").Get().Name}'", "fillMessage");
                }
            }
        }
コード例 #24
0
 private bool HasComponent(GameObject gameObject, System.Type type)
 {
     return(gameObject.GetComponents <Component>()
            .Where(t => type.IsInstanceOfType(t))
            .Any());
 }
コード例 #25
0
        internal static void HandleChildTransform(NetworkMessage netMsg)
        {
            NetworkInstanceId netId = netMsg.reader.ReadNetworkId();
            uint num = netMsg.reader.ReadPackedUInt32();

            NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Incoming, (short)16, "16:LocalChildTransform", 1);
            GameObject localObject = NetworkServer.FindLocalObject(netId);

            if ((UnityEngine.Object)localObject == (UnityEngine.Object)null)
            {
                if (!LogFilter.logError)
                {
                    return;
                }
                Debug.LogError((object)"HandleChildTransform no gameObject");
            }
            else
            {
                NetworkTransformChild[] components = localObject.GetComponents <NetworkTransformChild>();
                if (components == null || components.Length == 0)
                {
                    if (!LogFilter.logError)
                    {
                        return;
                    }
                    Debug.LogError((object)"HandleChildTransform no children");
                }
                else if ((long)num >= (long)components.Length)
                {
                    if (!LogFilter.logError)
                    {
                        return;
                    }
                    Debug.LogError((object)"HandleChildTransform childIndex invalid");
                }
                else
                {
                    NetworkTransformChild networkTransformChild = components[(IntPtr)num];
                    if ((UnityEngine.Object)networkTransformChild == (UnityEngine.Object)null)
                    {
                        if (!LogFilter.logError)
                        {
                            return;
                        }
                        Debug.LogError((object)"HandleChildTransform null target");
                    }
                    else if (!networkTransformChild.localPlayerAuthority)
                    {
                        if (!LogFilter.logError)
                        {
                            return;
                        }
                        Debug.LogError((object)"HandleChildTransform no localPlayerAuthority");
                    }
                    else if (!netMsg.conn.clientOwnedObjects.Contains(netId))
                    {
                        if (!LogFilter.logWarn)
                        {
                            return;
                        }
                        Debug.LogWarning((object)("NetworkTransformChild netId:" + (object)netId + " is not for a valid player"));
                    }
                    else
                    {
                        networkTransformChild.UnserializeModeTransform(netMsg.reader, false);
                        networkTransformChild.m_LastClientSyncTime = Time.time;
                        if (networkTransformChild.isClient)
                        {
                            return;
                        }
                        networkTransformChild.m_Target.localPosition = networkTransformChild.m_TargetSyncPosition;
                        networkTransformChild.m_Target.localRotation = networkTransformChild.m_TargetSyncRotation3D;
                    }
                }
            }
        }
コード例 #26
0
ファイル: UIButtonTween.cs プロジェクト: reaganq/mixabots
    /// <summary>
    /// Activate the tweeners.
    /// </summary>

    public void Play(bool forward)
    {
        GameObject go = (tweenTarget == null) ? gameObject : tweenTarget;

        if (!NGUITools.GetActive(go))
        {
            // If the object is disabled, don't do anything
            if (ifDisabledOnPlay != EnableCondition.EnableThenPlay)
            {
                return;
            }

            // Enable the game object before tweening it
            NGUITools.SetActive(go, true);
        }

        // Gather the tweening components
        mTweens = includeChildren ? go.GetComponentsInChildren <UITweener>() : go.GetComponents <UITweener>();

        if (mTweens.Length == 0)
        {
            // No tweeners found -- should we disable the object?
            if (disableWhenFinished != DisableCondition.DoNotDisable)
            {
                NGUITools.SetActive(tweenTarget, false);
            }
        }
        else
        {
            bool activated = false;
            if (playDirection == Direction.Reverse)
            {
                forward = !forward;
            }

            // Run through all located tween components
            for (int i = 0, imax = mTweens.Length; i < imax; ++i)
            {
                UITweener tw = mTweens[i];

                // If the tweener's group matches, we can work with it
                if (tw.tweenGroup == tweenGroup)
                {
                    // Ensure that the game objects are enabled
                    if (!activated && !NGUITools.GetActive(go))
                    {
                        activated = true;
                        NGUITools.SetActive(go, true);
                    }

                    // Toggle or activate the tween component
                    if (playDirection == Direction.Toggle)
                    {
                        tw.Toggle();
                    }
                    else
                    {
                        tw.Play(forward);
                    }
                    if (resetOnPlay)
                    {
                        tw.Reset();
                    }

                    // Set the delegate
                    tw.onFinished = onFinished;

                    // Copy the event receiver
                    if (eventReceiver != null && !string.IsNullOrEmpty(callWhenFinished))
                    {
                        tw.eventReceiver    = eventReceiver;
                        tw.callWhenFinished = callWhenFinished;
                    }
                }
            }
        }
    }
コード例 #27
0
        private static void ModifyContentInstance(string viewName, GameObject currentContentInstance, List <ContentInfo> currentContents)
        {
            var contentName = currentContentInstance.name.ToLower();

            // set default rect.
            var rectTrans = currentContentInstance.GetComponent <RectTransform>();

            rectTrans.anchoredPosition = new Vector2(0, 0);
            rectTrans.anchorMin        = new Vector2(0, 1);
            rectTrans.anchorMax        = new Vector2(0, 1);

            // 画像か文字を含んでいるコンテンツで、コードも可。でもボタンの実行に関しては画像に対してボタンが勝手にセットされる。ボタンをつけたらエラー。
            // 文字のリンク化も勝手に行われる。というかあれもボタンだっけ。
            // ボタンコンポーネントが付いていたら外す。
            if (currentContentInstance.GetComponent <Button>() != null)
            {
                throw new Exception("do not attach Button component directory. Button component will be attached automatically.");
            }

            var components = currentContentInstance.GetComponents <Component>();

            var type = TreeType.Content_Img;

            if (components.Length < 3)
            {
                type = TreeType.Content_Img;
            }
            else
            {
                // foreach (var s in components) {
                //     Debug.LogError("s:" + s.GetType().Name);
                // }

                // rectTrans, canvasRenderer 以外を採用する。
                var currentFirstComponent = components[2];

                switch (currentFirstComponent.GetType().Name)
                {
                case "Image": {
                    type = TreeType.Content_Img;
                    break;
                }

                case "Text": {
                    type = TreeType.Container;    // not Content_Text.
                    break;
                }

                default: {
                    throw new Exception("unsupported second component on content. found component type:" + currentFirstComponent);
                }
                }
            }

            // 名前を登録する
            currentContents.Add(new ContentInfo(contentName, type, "resources://" + ConstSettings.PREFIX_PATH_INFORMATION_RESOURCE + viewName + "/" + contentName.ToUpper()));

            // このコンポーネントをprefab化する
            {
                var prefabPath = "Assets/InformationResources/Resources/Views/" + viewName + "/" + contentName.ToUpper() + ".prefab";
                var dirPath    = Path.GetDirectoryName(prefabPath);

                FileController.CreateDirectoryRecursively(dirPath);
                PrefabUtility.CreatePrefab(prefabPath, currentContentInstance);

                // 自体の削除
                GameObject.DestroyImmediate(currentContentInstance);
            }
        }
コード例 #28
0
        protected virtual PersistentDescriptor CreateDescriptorAndData(GameObject go, List <PersistentObject> persistentData, List <long> persistentIdentifiers, /*HashSet<int> usings,*/ GetDepsFromContext getDepsFromCtx, PersistentDescriptor parentDescriptor = null)
        {
            if (go.GetComponent <RTSLIgnore>())
            {
                //Do not save persistent ignore objects
                return(null);
            }
            Type persistentType = m_typeMap.ToPersistentType(go.GetType());

            if (persistentType == null)
            {
                return(null);
            }

            long persistentID = ToID(go);
            //if(m_assetDB.IsResourceID(persistentID))
            //{
            //    int ordinal = m_assetDB.ToOrdinal(persistentID);
            //    usings.Add(ordinal);
            //}

            PersistentDescriptor descriptor = new PersistentDescriptor(m_typeMap.ToGuid(persistentType), persistentID, go.name);

            descriptor.Parent = parentDescriptor;

            PersistentObject goData = (PersistentObject)Activator.CreateInstance(persistentType);

            goData.ReadFrom(go);
            goData.GetDepsFrom(go, getDepsFromCtx);
            persistentData.Add(goData);
            persistentIdentifiers.Add(persistentID);

            Component[] components = go.GetComponents <Component>().Where(c => c != null).ToArray();
            if (components.Length > 0)
            {
                List <PersistentDescriptor> componentDescriptors = new List <PersistentDescriptor>();
                for (int i = 0; i < components.Length; ++i)
                {
                    Component component = components[i];
                    Type      persistentComponentType = m_typeMap.ToPersistentType(component.GetType());
                    if (persistentComponentType == null)
                    {
                        continue;
                    }

                    long componentID = ToID(component);
                    //if (m_assetDB.IsResourceID(componentID))
                    //{
                    //    int ordinal = m_assetDB.ToOrdinal(componentID);
                    //    usings.Add(ordinal);
                    //}
                    PersistentDescriptor componentDescriptor = new PersistentDescriptor(m_typeMap.ToGuid(persistentComponentType), componentID, component.name);
                    componentDescriptor.Parent = descriptor;
                    componentDescriptors.Add(componentDescriptor);

                    PersistentObject componentData = (PersistentObject)Activator.CreateInstance(persistentComponentType);
                    componentData.ReadFrom(component);
                    componentData.GetDepsFrom(component, getDepsFromCtx);
                    persistentData.Add(componentData);
                    persistentIdentifiers.Add(componentID);
                }

                if (componentDescriptors.Count > 0)
                {
                    descriptor.Components = componentDescriptors.ToArray();
                }
            }

            Transform transform = go.transform;

            if (transform.childCount > 0)
            {
                List <PersistentDescriptor> children = new List <PersistentDescriptor>();
                foreach (Transform child in transform)
                {
                    PersistentDescriptor childDescriptor = CreateDescriptorAndData(child.gameObject, persistentData, persistentIdentifiers, /*usings,*/ getDepsFromCtx, descriptor);
                    if (childDescriptor != null)
                    {
                        children.Add(childDescriptor);
                    }
                }

                descriptor.Children = children.ToArray();
            }

            return(descriptor);
        }
コード例 #29
0
    static public GameObject DoCopyObjects(GameObject from)
    {
        MegaModifyObject fromMod = from.GetComponent <MegaModifyObject>();

        GameObject to;

        if (fromMod)
        {
            to = CopyMesh(from, fromMod);
        }
        else
        {
            to = CopyMesh(from);
        }
        //CopyObject.CopyFromTo(from, to);

        //return to;
        MegaModifier[] desmods = to.GetComponents <MegaModifier>();
        for (int i = 0; i < desmods.Length; i++)
        {
            GameObject.DestroyImmediate(desmods[i]);
        }

        MegaModifyObject mo = to.GetComponent <MegaModifyObject>();

        if (mo)
        {
            GameObject.DestroyImmediate(mo);
            mo = to.AddComponent <MegaModifyObject>();

            CopyModObj(fromMod, mo);
        }

        MegaModifier[] mods = from.GetComponents <MegaModifier>();

        //for ( int i = 0; i < mods.Length; i++ )
        //{
        //	CopyComponent(mods[i], to);
        //}
        for (int i = 0; i < mods.Length; i++)
        {
            Component com = CopyComponent(mods[i], to);

            Type tp = com.GetType();

            if (tp.IsSubclassOf(typeof(MegaMorphBase)))
            {
                MegaMorphBase mor = (MegaMorphBase)com;
                // Need to rebuild the morphchan
                List <MegaMorphChan> chans = new List <MegaMorphChan>();

                for (int c = 0; c < mor.chanBank.Count; c++)
                {
                    MegaMorphChan chan = new MegaMorphChan();

                    MegaMorphChan.Copy(mor.chanBank[c], chan);
                    chans.Add(chan);
                }

                mor.chanBank = chans;
            }
        }


        if (mo)
        {
            //mod.ReStart1(false);

            //for ( int i = 0; i < mods.Length; i++ )
            //	mods[i].SetModMesh(mod.cachedMesh);
            mo.MeshUpdated();
        }
        to.name = from.name + " - Copy";
        return(to);
    }
コード例 #30
0
ファイル: SceneView.cs プロジェクト: ChrisLakeZA/duality
 protected GameObjectNode ScanGameObject(GameObject obj, bool scanChildren)
 {
     if (obj == null) return null;
     GameObjectNode thisNode = new GameObjectNode(obj, !this.buttonShowComponents.Checked);
     foreach (Component c in obj.GetComponents<Component>())
     {
         ComponentNode compNode = this.ScanComponent(c);
         if (compNode != null) this.InsertNodeSorted(compNode, thisNode);
     }
     if (scanChildren)
     {
         foreach (GameObject c in obj.Children)
         {
             GameObjectNode childNode = this.ScanGameObject(c, scanChildren);
             if (childNode != null) this.InsertNodeSorted(childNode, thisNode);
         }
     }
     return thisNode;
 }
コード例 #31
0
    static public void CopyFromTo(GameObject obj, GameObject to)
    {
        Component[] components = obj.GetComponents <Component>();

        for (int i = 0; i < components.Length; i++)
        {
            bool en = false;
            Type tp = components[i].GetType();

            if (tp.IsSubclassOf(typeof(Behaviour)))
            {
                en = (components[i] as Behaviour).enabled;
            }
            else
            {
                if (tp.IsSubclassOf(typeof(Component)) && tp.GetProperty("enabled") != null)
                {
                    en = (bool)tp.GetProperty("enabled").GetValue(components[i], null);
                }
                else
                {
                    en = true;
                }
            }

            FieldInfo[]    fields     = tp.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Default);       //claredOnly);
            PropertyInfo[] properties = tp.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Default);   //claredOnly);

            Component c = to.GetComponent(tp);

            if (c == null)
            {
                c = to.AddComponent(tp);
            }

            if (tp.IsSubclassOf(typeof(Behaviour)))
            {
                (c as Behaviour).enabled = en;
            }
            else
            {
                if (tp.IsSubclassOf(typeof(Component)) && tp.GetProperty("enabled") != null)
                {
                    tp.GetProperty("enabled").SetValue(c, en, null);
                }
            }

            for (int j = 0; j < fields.Length; j++)
            {
                fields[j].SetValue(c, fields[j]);
            }

            for (int j = 0; j < properties.Length; j++)
            {
                Debug.Log("prop " + properties[j].Name);

                //if ( properties[j].CanWrite )
                //	properties[j].SetValue(c, properties[j], null);
            }
        }
    }
コード例 #32
0
        protected void UpdateComponentEditors(GameObject[] values)
        {
            this.BeginUpdate();

            if (!this.Children.Any())
            {
                this.gameObjEditor.Getter = this.GetValue;
                this.gameObjEditor.Setter = this.SetValue;
                this.AddPropertyEditor(this.gameObjEditor);
            }
            Type[] typesInUse = values.GetComponents<Component>().Select(c => c.GetType()).Distinct().ToArray();

            // Remove Component editors that aren't needed anymore
            var cmpEditorCopy = new Dictionary<Type,PropertyEditor>(this.componentEditors);
            foreach (var pair in cmpEditorCopy)
            {
                if (!typesInUse.Contains(pair.Key))
                {
                    this.RemovePropertyEditor(pair.Value);
                    this.componentEditors.Remove(pair.Key);
                }
            }

            // Create the ones that are needed now and not added yet
            foreach (Type t in typesInUse)
            {
                if (!this.componentEditors.ContainsKey(t))
                {
                    PropertyEditor e = this.ParentGrid.CreateEditor(t, this);
                    e.Getter = this.CreateComponentValueGetter(t);
                    e.Setter = this.CreateComponentValueSetter(t);
                    e.PropertyName = t.GetTypeCSCodeName(true);
                    this.ParentGrid.ConfigureEditor(e);
                    this.AddPropertyEditor(e);
                    this.componentEditors[t] = e;
                }
            }

            this.EndUpdate();
        }
コード例 #33
0
ファイル: SaveLoadMenu.cs プロジェクト: Badeye/impulse
        public SceneObject PackGameObject(GameObject go)
        {

            ObjectIdentifier objectIdentifier = go.GetComponent<ObjectIdentifier>();

            //Now, we create a new instance of SceneObject, which will hold all the GO's data, including it's components.
            SceneObject sceneObject = new SceneObject();
            sceneObject.name = go.name;
            sceneObject.prefabName = objectIdentifier.prefabName;
            sceneObject.id = objectIdentifier.id;
            if (go.transform.parent != null && go.transform.parent.GetComponent<ObjectIdentifier>() == true)
            {
                sceneObject.idParent = go.transform.parent.GetComponent<ObjectIdentifier>().id;
            }
            else
            {
                sceneObject.idParent = null;
            }

            //in this case, we will only store MonoBehavior scripts that are on the GO. The Transform is stored as part of the ScenObject isntance (assigned further down below).
            //If you wish to store other component types, you have to find you own ways to do it if the "easy" way that is used for storing components doesn't work for them.
            List<string> componentTypesToAdd = new List<string>() {
            "UnityEngine.MonoBehaviour"
        };

            //This list will hold only the components that are actually stored (MonoBehavior scripts, in this case)
            List<object> components_filtered = new List<object>();

            //Collect all the components that are attached to the GO.
            //This includes MonoBehavior scripts, Renderers, Transform, Animator...
            //If it
            object[] components_raw = go.GetComponents<Component>() as object[];
            foreach (object component_raw in components_raw)
            {
                if (componentTypesToAdd.Contains(component_raw.GetType().BaseType.FullName))
                {
                    components_filtered.Add(component_raw);
                }
            }

            foreach (object component_filtered in components_filtered)
            {
                sceneObject.objectComponents.Add(PackComponent(component_filtered));
            }

            //Assign all the GameObject's misc. values
            sceneObject.position = go.transform.position;
            sceneObject.localScale = go.transform.localScale;
            sceneObject.rotation = go.transform.rotation;
            sceneObject.active = go.activeSelf;

            return sceneObject;
        }
コード例 #34
0
        protected virtual GameObject CreateHighlightModel(GameObject givenOutlineModel, string givenOutlineModelPath)
        {
            if (givenOutlineModel != null)
            {
                givenOutlineModel = (givenOutlineModel.GetComponent <Renderer>() ? givenOutlineModel : givenOutlineModel.GetComponentInChildren <Renderer>().gameObject);
            }
            else if (givenOutlineModelPath != "")
            {
                var getChildModel = transform.FindChild(givenOutlineModelPath);
                givenOutlineModel = (getChildModel ? getChildModel.gameObject : null);
            }

            GameObject copyModel = givenOutlineModel;

            if (copyModel == null)
            {
                copyModel = (GetComponent <Renderer>() ? gameObject : GetComponentInChildren <Renderer>().gameObject);
            }

            if (copyModel == null)
            {
                Debug.LogError("No Renderer has been found on the model to add highlighting to");
                return(null);
            }

            GameObject highlightModel = new GameObject(name + "_HighlightModel");

            highlightModel.transform.SetParent(copyModel.transform.parent, false);
            highlightModel.transform.localPosition = copyModel.transform.localPosition;
            highlightModel.transform.localRotation = copyModel.transform.localRotation;
            highlightModel.transform.localScale    = copyModel.transform.localScale;
            highlightModel.transform.SetParent(transform);

            foreach (var component in copyModel.GetComponents <Component>())
            {
                if (Array.IndexOf(copyComponents, component.GetType().ToString()) >= 0)
                {
                    VRTK_SharedMethods.CloneComponent(component, highlightModel);
                }
            }

            var copyMesh      = copyModel.GetComponent <MeshFilter>();
            var highlightMesh = highlightModel.GetComponent <MeshFilter>();

            if (highlightMesh)
            {
                if (enableSubmeshHighlight)
                {
                    List <CombineInstance> combine = new List <CombineInstance>();

                    for (int i = 0; i < copyMesh.mesh.subMeshCount; i++)
                    {
                        CombineInstance ci = new CombineInstance();
                        ci.mesh         = copyMesh.mesh;
                        ci.subMeshIndex = i;
                        ci.transform    = copyMesh.transform.localToWorldMatrix;
                        combine.Add(ci);
                    }

                    highlightMesh.mesh = new Mesh();
                    highlightMesh.mesh.CombineMeshes(combine.ToArray(), true, false);
                }
                else
                {
                    highlightMesh.mesh = copyMesh.mesh;
                }

                highlightModel.GetComponent <Renderer>().material = stencilOutline;
            }
            highlightModel.SetActive(false);

            VRTK_PlayerObject.SetPlayerObject(highlightModel, VRTK_PlayerObject.ObjectTypes.Highlighter);

            return(highlightModel);
        }
コード例 #35
0
        public override ExtendedEventArgs process()
        {
            Debug.Log ("loationResponse");

            ResponseRRPositionEventArgs args = new ResponseRRPositionEventArgs ();
            g = GameObject.Find ("GameLogic");
            p2 = g.GetComponents<Running> ();
            //<<<<<<< HEAD
            Debug.Log ("x = "+ x + "\ny = " + y );
            //		p2[0].player2.transform.position = new Vector3((float)x,(float)y,0f);
            //=======
            //Debug.Log ("response:    x = "+ x + "\ny = " + y );
            p2[0].player2.transform.position = new Vector3(x,y,0f);
            //>>>>>>> Dong

            args.x = x;
            args.y = y;
            return args;
        }
コード例 #36
0
        private static void     DrawOverlay(int instanceID, Rect selectionRect)
        {
            HierarchyEnhancerSettings settings = HQ.Settings.Get <HierarchyEnhancerSettings>();

            if ((NGHierarchyEnhancer.instance == null ||
                 // When an Object is destroyed, it returns null but is not null...
                 NGHierarchyEnhancer.instance.Equals(null) == true) &&
                NGHierarchyEnhancer.hierarchyType != null)
            {
                Object[] consoles = Resources.FindObjectsOfTypeAll(NGHierarchyEnhancer.hierarchyType);

                if (consoles.Length > 0)
                {
                    NGHierarchyEnhancer.instance = consoles[0] as EditorWindow;
                    NGHierarchyEnhancer.instance.wantsMouseMove = true;
                }
            }

            if (EditorWindow.mouseOverWindow == NGHierarchyEnhancer.instance)
            {
                // HACK Need to shift by one.
                // Ref Bug #720211_8cg6m8s7akdbf1r5
                if (settings.holdModifiers > 0)
                {
                    NGHierarchyEnhancer.holding = ((int)Event.current.modifiers & ((int)settings.holdModifiers)) == ((int)settings.holdModifiers);
                }
                if (settings.selectionHoldModifiers > 0)
                {
                    NGHierarchyEnhancer.selectionHolding = ((int)Event.current.modifiers & ((int)settings.selectionHoldModifiers)) == ((int)settings.selectionHoldModifiers);
                }
            }

            selectionRect.width += selectionRect.x;
            selectionRect.x      = 0F;

            Object obj;

            if (instanceID == NGHierarchyEnhancer.lastInstanceID)
            {
                obj = NGHierarchyEnhancer.lastObject;
            }
            else
            {
                obj = EditorUtility.InstanceIDToObject(instanceID);
                NGHierarchyEnhancer.lastInstanceID = instanceID;
                NGHierarchyEnhancer.lastObject     = obj;
                NGHierarchyEnhancer.lastBehaviours = null;
            }

            if (obj != null)
            {
                GameObject go = obj as GameObject;

                if (settings.layers != null &&
                    settings.layers.Length > go.layer &&
                    settings.layers[go.layer].a > 0F)
                {
                    EditorGUI.DrawRect(selectionRect, settings.layers[go.layer]);
                }

                if (settings.layersIcon != null &&
                    settings.layersIcon.Length > go.layer &&
                    settings.layersIcon[go.layer] != null)
                {
                    NGHierarchyEnhancer.ProcessIndentLevel(selectionRect.y, go);
                    GUI.DrawTexture(NGHierarchyEnhancer.indentRect, settings.layersIcon[go.layer], ScaleMode.ScaleToFit);
                }

                // Draw Component' color over layer's background color.
                go.GetComponents <Component>(cacheComponents);

                Rect r = selectionRect;

                if (settings.widthPerComponent > 0F)
                {
                    NGHierarchyEnhancer.ProcessIndentLevel(selectionRect.y, go);
                    r = NGHierarchyEnhancer.indentRect;

                    for (int i = 1; i < cacheComponents.Count; i++)                     // Skip Transform.
                    {
                        if (cacheComponents[i] == null)
                        {
                            continue;
                        }

                        bool drawn = false;
                        Type t     = cacheComponents[i].GetType();

                        if (settings.drawUnityComponents == true)
                        {
                            int k = 0;

                            r.width = 16F;

                            for (; k < NGHierarchyEnhancer.unityComponentData.Count; k++)
                            {
                                if (t == NGHierarchyEnhancer.unityComponentData[k].type)
                                {
                                    if (NGHierarchyEnhancer.unityComponentData[k].icon != null)
                                    {
                                        GUI.DrawTexture(r, NGHierarchyEnhancer.unityComponentData[k].icon);
                                        r.x  += r.width;
                                        drawn = true;
                                    }
                                    break;
                                }
                            }

                            if (k < NGHierarchyEnhancer.unityComponentData.Count)
                            {
                                if (drawn == true)
                                {
                                    continue;
                                }
                            }
                            else if (t.Assembly != typeof(Editor).Assembly)
                            {
                                NGHierarchyEnhancer.unityComponentData.Add(new HierarchyEnhancerSettings.ComponentColor()
                                {
                                    type = t, icon = EditorGUIUtility.ObjectContent(null, t).image
                                });
                            }
                        }

                        for (int j = 0; j < settings.componentData.Length; j++)
                        {
                            if (settings.componentData[j].type == null)
                            {
                                continue;
                            }

                            if (t == settings.componentData[j].type)
                            {
                                if (settings.componentData[j].icon != null)
                                {
                                    r.width = 16F;
                                    GUI.DrawTexture(r, settings.componentData[j].icon);
                                }
                                else
                                {
                                    r.width = settings.widthPerComponent;
                                    EditorGUI.DrawRect(r, settings.componentData[j].color);
                                }

                                r.x += r.width;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    for (int j = 0; j < settings.componentData.Length; j++)
                    {
                        if (settings.componentData[j].type == null)
                        {
                            continue;
                        }

                        int i = 0;

                        for (; i < cacheComponents.Count; i++)
                        {
                            if (cacheComponents[i].GetType() == settings.componentData[j].type)
                            {
                                EditorGUI.DrawRect(r, settings.componentData[j].color);
                                break;
                            }
                        }

                        if (i < cacheComponents.Count)
                        {
                            break;
                        }
                    }
                }
            }

            if (NGHierarchyEnhancer.IsInSelection(obj) ||
                (selectionRect.Contains(Event.current.mousePosition) == true && NGHierarchyEnhancer.holding == false) ||
                (NGHierarchyEnhancer.holding == true && NGHierarchyEnhancer.lastInstanceId == instanceID))
            {
                if (NGHierarchyEnhancer.lastInstanceId != instanceID &&
                    NGHierarchyEnhancer.holding == false)
                {
                    NGHierarchyEnhancer.lastInstanceId = instanceID;
                    NGHierarchyEnhancer.menuOpen       = false;
                }

                if (Event.current.type == EventType.MouseMove)
                {
                    NGHierarchyEnhancer.instance.Repaint();
                }

                if (obj != null)
                {
                    float x     = selectionRect.x;
                    float width = selectionRect.width;

                    selectionRect.x    += selectionRect.width - 30F - settings.margin;
                    selectionRect.width = 30F;

                    if ((NGHierarchyEnhancer.selectionHolding == true && NGHierarchyEnhancer.IsInSelection(obj)) ||
                        NGHierarchyEnhancer.holding == true ||
                        selectionRect.Contains(Event.current.mousePosition) == true)
                    {
                        if (NGHierarchyEnhancer.menuOpen == false)
                        {
                            NGHierarchyEnhancer.menuOpen = true;
                            NGHierarchyEnhancer.instance.Repaint();
                        }
                    }

                    if (NGHierarchyEnhancer.menuOpen == false)
                    {
                        GUI.Button(selectionRect, "NG");
                    }
                    else
                    {
                        selectionRect.x     = 0F;
                        selectionRect.width = width + x - settings.margin;

                        EditorGUI.BeginChangeCheck();

                        // Draws DynamicObjectMenu first.

                        if (NGHierarchyEnhancer.objectMenus == null)
                        {
                            List <DynamicObjectMenu> menus = new List <DynamicObjectMenu>();

                            foreach (Type c in Utility.EachNGTSubClassesOf(typeof(DynamicObjectMenu)))
                            {
                                menus.Add(Activator.CreateInstance(c) as DynamicObjectMenu);
                            }

                            menus.Sort((a, b) => a.priority - b.priority);
                            NGHierarchyEnhancer.objectMenus = menus.ToArray();
                        }

                        for (int i = 0; i < NGHierarchyEnhancer.objectMenus.Length; i++)
                        {
                            // Shrink available width with new end point on X axis.
                            selectionRect.width = NGHierarchyEnhancer.objectMenus[i].DrawHierarchy(selectionRect, obj) - selectionRect.x;
                        }

                        if (EditorGUI.EndChangeCheck() == true)
                        {
                            Metrics.UseTool(12);                             // NGHierarchyEnhancer
                            NGChangeLogWindow.CheckLatestVersion(NGAssemblyInfo.Name);
                        }

                        // Then all sub-implementations.
                        GameObject gameObject = obj as GameObject;

                        if (gameObject != null)
                        {
                            Behaviour[] behaviours;

                            if (NGHierarchyEnhancer.lastBehaviours == null)
                            {
                                behaviours = gameObject.GetComponents <Behaviour>();
                                NGHierarchyEnhancer.lastBehaviours = behaviours;
                            }
                            else
                            {
                                behaviours = NGHierarchyEnhancer.lastBehaviours;
                            }

                            for (int i = 0; i < behaviours.Length; i++)
                            {
                                if (behaviours[i] == null)
                                {
                                    continue;
                                }

                                INGHierarchyEnhancerGUI drawer = behaviours[i] as INGHierarchyEnhancerGUI;

                                if (drawer != null)
                                {
                                    selectionRect.width = drawer.OnHierarchyGUI(selectionRect) - selectionRect.x;
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #37
0
 private static void SetVis(GameObject go, bool vis)
 {
   foreach (Renderer component in go.GetComponents<Renderer>())
     component.enabled = vis;
   for (int index = 0; index < go.transform.childCount; ++index)
     NetworkProximityChecker.SetVis(go.transform.GetChild(index).gameObject, vis);
 }
コード例 #38
0
        internal static void HandleChildTransform(NetworkMessage netMsg)
        {
            NetworkInstanceId networkInstanceId = netMsg.reader.ReadNetworkId();
            uint       num        = netMsg.reader.ReadPackedUInt32();
            GameObject gameObject = NetworkServer.FindLocalObject(networkInstanceId);

            if (gameObject == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("HandleChildTransform no gameObject");
                }
                return;
            }
            NetworkTransformChild[] components = gameObject.GetComponents <NetworkTransformChild>();
            if (components == null || components.Length == 0)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("HandleChildTransform no children");
                }
                return;
            }
            if (num >= components.Length)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("HandleChildTransform childIndex invalid");
                }
                return;
            }
            NetworkTransformChild networkTransformChild = components[num];

            if (networkTransformChild == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("HandleChildTransform null target");
                }
                return;
            }
            if (!networkTransformChild.localPlayerAuthority)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("HandleChildTransform no localPlayerAuthority");
                }
                return;
            }
            if (!netMsg.conn.clientOwnedObjects.Contains(networkInstanceId))
            {
                if (LogFilter.logWarn)
                {
                    Debug.LogWarning("NetworkTransformChild netId:" + networkInstanceId + " is not for a valid player");
                }
                return;
            }
            networkTransformChild.UnserializeModeTransform(netMsg.reader, initialState: false);
            networkTransformChild.m_LastClientSyncTime = Time.time;
            if (!networkTransformChild.isClient)
            {
                networkTransformChild.m_Target.localPosition = networkTransformChild.m_TargetSyncPosition;
                networkTransformChild.m_Target.localRotation = networkTransformChild.m_TargetSyncRotation3D;
            }
        }
コード例 #39
0
 // disable rendering of gameobjects the host should not see. He does not use network bandwidth anyway, so just non rendering is needed
 private static void SetVis(GameObject go, bool vis)
 {
     Renderer[] components = go.GetComponents<Renderer>();
     for (int i = 0; i < components.Length; i++)
     {
         Renderer renderer = components[i];
         renderer.set_enabled(vis);
     }
     for (int j = 0; j < go.get_transform().get_childCount(); j++)
     {
         Transform child = go.get_transform().GetChild(j);
         NetworkProximityChecker.SetVis(child.get_gameObject(), vis);
     }
 }
コード例 #40
0
 /// <summary>
 /// Get all bindable Unity events on a particular game object.
 /// </summary>
 public static BindableEvent[] GetBindableEvents(GameObject gameObject) //todo: Consider moving this to TypeResolver.
 {
     return(gameObject.GetComponents(typeof(Component))
            .SelectMany(component => GetBindableEvents(component))
            .ToArray());
 }
コード例 #41
0
ファイル: AutoMove.cs プロジェクト: KaluginaMarina/DreamGame
    // FixedUpdate is called once per frame
    void FixedUpdate()
    {
        if (!IsGameOn && Input.anyKey && CountWithCamera >= BadGuys.Count)
        {
            level = 1;
            goodGuy.GetComponentsInChildren <UnityEngine.UI.Text>()[2].text = "";
            goodGuy.GetComponentsInChildren <UnityEngine.UI.Text>()[3].text = "";

            generate.GetComponents <Generate>()[0].RegenerateLevel();
        }

        if (IsGameOn && IsStart)
        {
            if (_frameCount-- < 0)
            {
                _frameCount = rand.Next(50, 200);
                direction   = RandDirection();
            }

            withCamera = false;

            if (CheckGoodGuyDistance(15) && !CheckGoodGuyPlace())
            {
                var position1 = goodGuy.transform.position;
                var position2 = badGuy.transform.position;
                direction.x = -(position2.x - position1.x) * 2;
                direction.y = -(position2.y - position1.y) * 2;
            }

            if (CheckGoodGuyDistance(4) && !CheckGoodGuyPlace())
            {
                goodGuy.GetComponentsInChildren <UnityEngine.UI.Text>()[2].text = "Game Over";
                IsGameOn = false;
                IsStart  = false;
                var position2 = badGuy.transform.position;
                CountWithCamera++;
                Cameras.Add(Instantiate(camera, new Vector2((float)(position2.x), (float)(position2.y - 0.3)), Quaternion.identity));
                print("Game Over");
                withCamera = true;
            }

            var position = badGuy.transform.position;
            if (badGuy.transform.position.x < x1 + 1.5)
            {
                if (direction.x < 0)
                {
                    direction.x = 0;
                }
                position.Set(x1, position.y, 0);
            }
            else if (badGuy.transform.position.x > x2 - 1.5)
            {
                if (direction.x > 0)
                {
                    direction.x = 0;
                }
                position.Set(x2, position.y, 0);
            }

            if (badGuy.transform.position.y > y1)
            {
                if (direction.y > 0)
                {
                    direction.y = 0;
                }
                position.Set(position.x, y1, 0);
            }
            else if (badGuy.transform.position.y < y2)
            {
                if (direction.y < 0)
                {
                    direction.y = 0;
                }
                position.Set(position.x, y2, 0);
            }

            rigidbody2D.AddForce(direction * 6f);
        }
        else if (!IsGameOn)
        {
            if (!CheckGoodGuyDistance(4))
            {
                var position1 = goodGuy.transform.position;
                var position2 = badGuy.transform.position;
                direction.x = -(position2.x - position1.x) * 2;
                direction.y = -(position2.y - position1.y) * 2;
                rigidbody2D.AddForce(direction * 6f);
            }
            else
            {
                if (!withCamera)
                {
                    var position2 = badGuy.transform.position;
                    Cameras.Add(Instantiate(camera, new Vector2((float)(position2.x + 0.05), (float)(position2.y + 0.05)),
                                            Quaternion.identity));
                    withCamera = true;
                    CountWithCamera++;
                    if (CountWithCamera == BadGuys.Count)
                    {
                        goodGuy.GetComponentsInChildren <UnityEngine.UI.Text>()[3].text = "Нажмите любую клавишу, чтобы играть заново.";
                    }
                }
            }
        }
    }
コード例 #42
0
    private void DrawEffectsPanel()
    {
        effects_panel = new Rect(position.width * size_ratio + offset, 0, position.width * (1 - size_ratio) - offset * 2, position.height);

        GUILayout.BeginArea(effects_panel);
        GUILayout.Label("Effects");
        EditorGUILayout.BeginHorizontal();
        bool untargeted = GUILayout.Button("Untargeted Effect");
        bool targeted   = GUILayout.Button("Targeted Effect");
        //bool _static = GUILayout.Button("Static Effect");
        bool triggered = GUILayout.Button("Triggered Ability");

        // Search
        if (targeted || untargeted || triggered)
        {
            EffectPopupWindow window = null;

            if (targeted)
            {
                window = new EffectPopupWindow(new Vector2(effects_panel.width, (300 < effects_panel.height / 2f ? 300 : effects_panel.height / 2f)),
                                               "Assets/Scripts/Effects/Targeted",
                                               AddComponentToLoadedHeroPower);
            }
            else if (untargeted)
            {
                window = new EffectPopupWindow(new Vector2(effects_panel.width, (300 < effects_panel.height / 2f ? 300 : effects_panel.height / 2f)),
                                               "Assets/Scripts/Effects/Untargeted",
                                               AddComponentToLoadedHeroPower);
            }
            else if (triggered)
            {
                window = new EffectPopupWindow(new Vector2(effects_panel.width, (300 < effects_panel.height / 2f ? 300 : effects_panel.height / 2f)),
                                               "Assets/Scripts/Triggers/Triggers",
                                               AddComponentToLoadedHeroPower);
            }
            //else if (_static) {
            //    window = new EffectPopupWindow(new Vector2(effects_panel.width, (300 < effects_panel.height / 2f ? 300 : effects_panel.height / 2f)),
            //        "Assets/Scripts/Statics/Statics",
            //        AddComponentToLoadedCard);
            //}

            popup_rect.x = 0;
            PopupWindow.Show(popup_rect, window);
        }
        if (Event.current.type == EventType.Repaint)
        {
            popup_rect = GUILayoutUtility.GetLastRect();
        }
        EditorGUILayout.EndHorizontal();


        foreach (Effect e in loaded_hero_power.GetComponents <Effect>())
        {
            EffectFoldout(e);
        }
        //foreach (StaticAbility sa in loaded_hero_power.GetComponents<StaticAbility>()) {
        //    StaticsFoldout(sa);
        //}
        foreach (TriggeredAbility ta in loaded_hero_power.GetComponents <TriggeredAbility>())
        {
            TriggersFoldout(ta);
        }

        GUILayout.EndArea();
    }